import { Module } from '@nestjs/common';
import { PassportModule } from '@nestjs/passport';
import { TypeOrmModule } from '@nestjs/typeorm';
import { RedisModule } from 'nestjs-redis';
import { CommonModule } from './modules/common/common.module';
import { ConfigModule } from './modules/config/config.module';
import { ConfigService } from './modules/config/services/config.service';
import { ConfigProvider } from './modules/config/constants/config.constant';
import { LantUtil } from './utils/lant.util';
import { RegexUtil } from './utils/regex.util';
import { LogModule } from './modules/log/log.module';
import { JwtAnonymousStrategy } from './strategies/jwt-anonymous.strategy';
import { JwtStrategy } from './strategies/jwt.strategy';
import { UserModule } from './modules/user/user.module';
import { RoleModule } from './modules/role/role.module';
import { GuardModule } from './modules/guard/guard.module';
import { OrganizationModule } from './modules/organization/organization.module';
import { AreaModule } from './modules/area/area.module';
import { GeetestModule } from './modules/geetest/geetest.module';

@Module({
  imports: [
    TypeOrmModule.forRootAsync({
      useFactory: (configService: ConfigService) => configService.database,
      inject: [ConfigProvider]
    }),
    RedisModule.forRootAsync({
      useFactory: (configService: ConfigService) => [configService.redis.token],
      inject: [ConfigProvider]
    }),
    PassportModule.register({ defaultStrategy: 'bearer' }),
    ConfigModule,
    CommonModule,
    LogModule,
    GuardModule,
    OrganizationModule,
    UserModule,
    RoleModule,
    GeetestModule,
    AreaModule
  ],
  providers: [LantUtil, RegexUtil, JwtStrategy, JwtAnonymousStrategy],
  exports: [PassportModule.register({ defaultStrategy: 'bearer' }), JwtStrategy, JwtAnonymousStrategy, LantUtil, RegexUtil]
})
export class AppModule {}
